package Views;

import Types.AccountType;
import java.awt.*;
import javax.swing.*;

/**
 * the main user interface iin which all the gui data is displayed
 * @author Josh
 */
public class MainUI extends JFrame {

    private JPanel topPanel = new JPanel();
    private JPanel leftPanel = new JPanel();
    private JPanel bottomPanel = new JPanel();
    private ViewLoginUser loginPanel = new ViewLoginUser(this);
    private ViewDisplayCreateUser registerPanel = new ViewDisplayCreateUser(this);
    private ViewDisplayFlights displayFlightsPanel = new ViewDisplayFlights(this);
    private ViewCreateUser createUserPanel = new ViewCreateUser(this);
    private JPanel flightsPanel;
    private ViewDeleteUser deleteUserPanel = new ViewDeleteUser(this);
    private BorderLayout layout = new BorderLayout();
    private static AccountType onlineUser = new AccountType();

    /**
     * The constructor initualises main panels
     */
    public MainUI() {
        this.setLayout(layout);
        this.add(topPanel, BorderLayout.NORTH);
        this.add(leftPanel, BorderLayout.WEST);
        this.add(bottomPanel, BorderLayout.SOUTH);
        topPanel.setLayout(new FlowLayout());
        topPanel.add(loginPanel);
        topPanel.add(registerPanel);
        leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
        leftPanel.add(displayFlightsPanel);
        this.setTitle("Flights");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.pack();
        this.setVisible(true);
    }

    /**
     * gets the create user panel
     * @return
     */
    public Component getCreateUserPanel() {
        return createUserPanel;
    }

    /**
     * sets the flights panel
     * @param flightsPanel
     */
    public void setFlightsPanel(JPanel flightsPanel) {
        this.flightsPanel = flightsPanel;
        flightsPanel.setVisible(true);
        this.pack();
    }

    /**
     * gets the flight panel
     * @return
     */
    public Component getFlightsPanel() {
        return flightsPanel;
    }

    /**
     * adds the delete button
     */
    void addDeleteButton() {
        leftPanel.add(deleteUserPanel);
        this.pack();
    }

    /**
     * It removes the component that is located in the border layout centre area
     */
    void removeCenterPanel() {
        if (layout.getLayoutComponent(BorderLayout.CENTER) != null) {
            this.remove(layout.getLayoutComponent(BorderLayout.CENTER));
        }
    }

    /**
     * gets the online user data
     * @return
     */
    public static AccountType getOnlineUser() {
        return onlineUser;
    }

    /**
     * sets the online user data
     * @param onlineUser
     */
    public static void setOnlineUser(AccountType onlineUser) {
        MainUI.onlineUser = onlineUser;
    //loginPanel.updateUISuccess(onlineUser.getUsername());
    }

    /**
     * gets the login panel
     * @return
     */
    public ViewLoginUser getLoginPanel() {
        return loginPanel;
    }
}
